package com.czy.owner.ui.login;

import android.graphics.Bitmap;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.czy.owner.R;
import com.czy.owner.global.Constants;
import com.czy.owner.ui.BaseActivity;

import butterknife.BindView;

/**
 * Created by wangyang on 2016/7/22 0022.
 */

public class AgreeMentActivity extends BaseActivity {
    @BindView(R.id.webview)
    WebView webview;
    private String postDate;
    private String url;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_webview;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        getToolbarTitle().setText(R.string.user_agreement);
        url = Constants.APP_API_BASE + Constants.OWN_APPPROTOCOL;
        webview.setWebViewClient(new MyWebViewClient());
        WebSettings ws = webview.getSettings();
        ws.setJavaScriptEnabled(true);
        ws.setUseWideViewPort(false);  //将图片调整到适合webview的大小
        ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭webview中缓存
        webview.postUrl(url, null);
    }

    @Override
    protected void updateViews() {

    }

    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.postUrl(url, postDate.getBytes());
            return super.shouldOverrideUrlLoading(view, url);

        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mLoadView.CancleLoadView();
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);

            mLoadView.ShowLoadView();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        webview.destroy();
    }


}
